package com.example.shouybl.adapter;

import android.content.Context;

import android.view.View;
import android.view.ViewGroup;

import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.shouybl.R;
import com.example.shouybl.bean.GiftData;

import com.example.shouybl.utils.ImageLoaderUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2015/10/9.
 */
public class GiftMobileAdapter extends AppBaseAdapter<GiftData> {


    private final DisplayImageOptions options;

    public GiftMobileAdapter(List<GiftData> list, Context context) {
        super(list, context);
        options = ImageLoaderUtil.getDefaultOptions();
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        GiftData giftData=list.get(position);
        ViewHolder vh=ViewHolder.get(context,convertView,parent,R.layout.item_gift_shared_layout);
        ImageView ivIcon= (ImageView) vh.findViewById(R.id.iv_mobile_icon);
        TextView tvName= (TextView) vh.findViewById(R.id.tv_mobile_name);
        TextView tvContent= (TextView) vh.findViewById(R.id.tv_mobile_content);
        TextView tvRemain= (TextView) vh.findViewById(R.id.tv_mobile_remain);
        Button btnConsume= (Button) vh.findViewById(R.id.btn_mobile_consume);

        tvName.setText(giftData.getName());
        tvContent.setText(giftData.getContent());
        tvRemain.setText("剩余" + giftData.getRemain());
        ImageLoader.getInstance().displayImage(giftData.getIcon(),ivIcon,options);
        if (giftData.getConsume().equals("0.0")){
            if (giftData.getRemain()==0){
                btnConsume.setText("抢号");
            }else {
                btnConsume.setText("免费领取");
            }
        }else {
            btnConsume.setText(giftData.getConsume()+"Q币");
        }
        btnConsume.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return vh;
    }
}
